<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/3/12/012
 * Time: 15:08
 */

namespace app\project\controller;


use app\common\controller\Common;
use think\Controller;
use think\Db;
use think\Exception;
use think\Session;

require_once ROOT_PATH . "extend/PHPExce/PHPExcel.php";

class Excel extends Controller
{

    public function whereApi($getdata, $where)
    {
        if (!empty($getdata['visit_remark'])) {
            $visit_remark = $getdata['visit_remark'];
            $where['visit_remark'] = ['like', "%{$visit_remark}%"];
        }
        if (!empty($getdata['keyword'])) {
            $keyword = $getdata['keyword'];
            $where['title'] = ['like', "%{$keyword}%"];
        }
        if (!empty($getdata['code'])) {
            $code = $getdata['code'];
            $where['code'] = ['like', "%{$code}%"];
        }
        if (!empty($getdata['nature'])) {
            $nature = $getdata['nature'];
            $where['nature'] = $nature;
        }
        if (!empty($getdata['project_status'])) {
            $project_status = $getdata['project_status'];
            $where['project_status'] = $project_status - 1;
        }
        if (!empty($getdata['sign'])) {
            $where['sign'] = $getdata['sign'];
        }
        if (!empty($getdata['start_status'])) {
            $where['start_status'] = $getdata['start_status'];
        }
        if (!empty($getdata['warehousing'])) {
            $where['warehousing'] = $getdata['warehousing'];
        }
        if (!empty($getdata['reply'])) {
            $where['reply'] = $getdata['reply'];
        }
        if (!empty($getdata['duty_unit'])) {
            $duty_unit = $getdata['duty_unit'];
            $where['duty_unit'] = ['like', "%{$duty_unit}%"];
        }
        if (!empty($getdata['leader'])) {
            $leader = $getdata['leader'];
            $where['leader'] = ['like', "%{$leader}%"];
        }
        if (!empty($getdata['operation'])) {
            $where['operation'] = $getdata['operation'];
        }
        if (!empty($getdata['condition_val'])) {
            $where['condition_val'] = $getdata['condition_val'];
        }
        if (!empty($getdata['menuTop'])) {
            $where['menuTop'] = $getdata['menuTop'];
        }
        if (!empty($getdata['duty_person'])) {
            $duty_person = $getdata['duty_person'];
            $where['duty_person'] = ['like', "%{$duty_person}%"];
        }
        if (!empty($getdata['project_type'])) {
            $project_type = $getdata['project_type'];
            $where['project_type'] = $project_type;
        }
        if (!empty($getdata['enterprise'])) {
            $enterprise = $getdata['enterprise'];
            $where['enterprise'] = $enterprise;
        }
        return $where;
    }

    //取字段
    public function arrangeField($list,$library,$header_data){

        $sign = [1=>'未签约',2=>'已签约',3=>'已逾期',4=>'无法签约'];
        $start_status = [1=>'待开工',2=>'已开工',3=>'已逾期',4=>'已终止'];
        $warehousing = [1=>'待入库',2=>'已入库'];
        $project_status = [0=>"基础开工",1=>'已竣工',2=>'主体开工',3=>'已终止'];
        if ($library == 4){
            $project_status = [0=>"正常",1=>'逾期',2=>'已完工',3=>'无法推进'];
        }
        $reply = [1=>'已启报',2=>'已报竭'];
        $operation = [1=>'正常',2=>'异常'];
        $condition_val = [1=>'运行正常企业',2=>'一般困难企业',3=>'特别困难企业',4=>'停产企业'];

        $menuTop = [1=>"培育类",2=>"进规进限类"];

        foreach ($list as $item) {
            foreach ($header_data as $v){
                $data[$v] = $item[$v];
                if($v=='content'){
                    $data[$v] = strip_tags($item[$v]);
                }
                if($v=='sign'){
                    $data[$v] = empty($sign[$item[$v]])?"":$sign[$item[$v]];
                }
                if($v=='start_status'){
                    $data[$v] = empty($start_status[$item[$v]])?"":$start_status[$item[$v]];
                }
                if($v=='warehousing'){
                    $data[$v] = empty($warehousing[$item[$v]])?"":$warehousing[$item[$v]];
                }
                if($v=='project_status'){
                    $data[$v] = empty($project_status[$item[$v]])?"":$project_status[$item[$v]];
                }
                if($v=='reply'){
                    $data[$v] = empty($reply[$item[$v]])?"":$reply[$item[$v]];
                }
                if($v=='operation'){
                    $data[$v] = empty($operation[$item[$v]])?"":$operation[$item[$v]];
                }
                if($v=='condition_val'){
                    $data[$v] = empty($condition_val[$item[$v]])?"":$condition_val[$item[$v]];
                }
                if($v=='menuTop'){
                    $data[$v] = empty($menuTop[$item[$v]])?"":$menuTop[$item[$v]];
                }

                if($v=='enterprise'){
                    //查询
                    $typeWhere['id'] = $item[$v];
                    $typeName = Db::name("project_type")->where($typeWhere)->value("name");
                    $data[$v] = empty($typeName)?"":$typeName;
                }
                if($v=='visit_remark' || $v=='problem_content'){
                    $data[$v] = ($item[$v]=='undefined')?"":$item[$v];
                }

            }
            $list_do[] = $data;
        }
        return $list_do;
    }


    //双千库导出
    public function sqkExcel(){
        $list = [];
        $common = new Common();
        $library = empty($_GET['library']) ? 0 : $_GET['library'];

        $where['b.library'] = ['like', "%{$library}%"];

        $order = "visit_time desc,sort desc,id desc";

        $getdata = $_GET;
        if (!empty($getdata['visit_remark'])) {
            $visit_remark = $getdata['visit_remark'];
            $where['b.visit_remark'] = ['like', "%{$visit_remark}%"];
        }
        if (!empty($getdata['keyword'])) {
            $keyword = $getdata['keyword'];
            $where['b.title'] = ['like', "%{$keyword}%"];
        }
        if (!empty($getdata['code'])) {
            $code = $getdata['code'];
            $where['b.code'] = ['like', "%{$code}%"];
        }
        if (!empty($getdata['nature'])) {
            $nature = $getdata['nature'];
            $where['b.nature'] = $nature;
        }
        if (!empty($getdata['project_status'])) {
            $project_status = $getdata['project_status'];
            $where['b.project_status'] = $project_status - 1;
        }
        if (!empty($getdata['sign'])) {
            $where['b.sign'] = $getdata['sign'];
        }
        if (!empty($getdata['start_status'])) {
            $where['b.start_status'] = $getdata['start_status'];
        }
        if (!empty($getdata['warehousing'])) {
            $where['b.warehousing'] = $getdata['warehousing'];
        }
        if (!empty($getdata['reply'])) {
            $where['b.reply'] = $getdata['reply'];
        }
        if (!empty($getdata['duty_unit'])) {
            $duty_unit = $getdata['duty_unit'];
            $where['b.duty_unit'] = ['like', "%{$duty_unit}%"];
        }
        if (!empty($getdata['leader'])) {
            $leader = $getdata['leader'];
            $where['b.leader'] = ['like', "%{$leader}%"];
        }
        if (!empty($getdata['operation'])) {
            $where['b.operation'] = $getdata['operation'];
        }
        if (!empty($getdata['condition_val'])) {
            $where['b.condition_val'] = $getdata['condition_val'];
        }
        if (!empty($getdata['menuTop'])) {
            $where['b.menuTop'] = $getdata['menuTop'];
        }
        if (!empty($getdata['duty_person'])) {
            $duty_person = $getdata['duty_person'];
            $where['b.duty_person'] = ['like', "%{$duty_person}%"];
        }
        if (!empty($getdata['project_type'])) {
            $project_type = $getdata['project_type'];
            $where['b.project_type'] = $project_type;
        }
        if (!empty($getdata['enterprise'])) {
            $enterprise = $getdata['enterprise'];
            $where['b.enterprise'] = $enterprise;
        }

        $year = empty($getdata['year'])?date("Y"):$getdata['year'];
        $month = empty($getdata['month'])?"":$getdata['month'];

        if(empty($month)){
            $this->error("请选择月份");
        }

        if(!empty($month)){
            $show_time = $year."-".$month;
            $where['a.show_time'] = ['like',"%".$show_time."%"];
        }

        $list = Db::name("project_pro_figure")->alias("a")
            ->join("project_pro b","a.pro_id=b.id")
            ->where($where)
            ->field("b.*,a.content,a.show_time,a.problem_content,a.problem_id")
            ->select();

        foreach ($list as $k=>$v){
            unset($where);
            $where['id'] = $v['problem_id'];
            $typeName = $common->public_select("project_type",$where)->value("name");
            $list[$k]['typeName'] = empty($typeName)?"":$typeName;
        }
        $list_do = [];
        $header_arr = ['企业名称', '责任账号', '运行情况', '运营情况', '一级分类', '企业类型','走访时间','走访内容','存在的问题','诉求类型','问题内容'];
        $header_data = ['title','duty_person','condition_val','operation','menuTop','enterprise','visit_time','content','visit_remark','typeName','problem_content'];
        $list_do = $this->arrangeField($list,$library,$header_data);
        $libraryName = "双千库";
        return self::export_excel($header_arr, $list_do,$libraryName);
    }



    //导出操作
    public function business_excel()
    {
        $list = [];
        $common = new Common();
        $library = empty($_GET['library']) ? 0 : $_GET['library'];

        $where['library'] = ['like', "%{$library}%"];

        if ($library == 6) {
            $order = "visit_time desc,sort desc,id desc";
        } else {
            $order = "sort desc,id desc";
        }

        $where = $this->whereApi($_GET, $where);

        $list = $common->public_select("project_pro", $where, null)->order($order)->select();


        $list_do = [];
        /*foreach ($list as $item) {
            $data["title"] = $item["title"];
            $list_do[] = $data;
        }*/

        $header_arr = [];
        $libraryName = "项目列表";
        switch ($library){
            case 1: //招商签约库
                $header_arr = ['项目名称', '责任单位', '计划签约时间', '投资额（万元）', '签约状态', '建设内容'];
                $header_data = ['title','duty_unit','signTime','investment','sign','content'];
                $list_do = $this->arrangeField($list,$library,$header_data);
                $libraryName = "招商签约库";
                break;
            case 2:  //预备库
                $header_arr = ['项目名称', '责任单位', '计划开工时间', '实际开工时间', '开工状态','投资额（万元）', '建设内容'];
                $header_data = ['title','duty_unit','plan_onstream_time','onstream_time','start_status','investment','content'];
                $list_do = $this->arrangeField($list,$library,$header_data);
                $libraryName = "预备库";
                break;
            case 3:  //开工库
                $header_arr = ['项目名称', '总投资（万元）', '入库状态', '项目状态', '实际开工时间', '计划竣工时间','建设规模及内容','责任单位'];
                $header_data = ['title','investment','warehousing','project_status','onstream_time','plan_complete_time','content','duty_unit'];
                $list_do = $this->arrangeField($list,$library,$header_data);
                $libraryName = "开工库";
                break;
            case 4: //重点库  111
                $header_arr = ['项目名称', '责任单位', '项目状态', '县级领导', '项目估算总投资（万元）', '建设规模及内容'];
                $header_data = ['title','duty_unit','project_status','leader','investment','content'];
                $list_do = $this->arrangeField($list,$library,$header_data);
                $libraryName = "重点库";
                break;
            case 5:  //入统库
                $header_arr = ['项目名称', '责任单位', '入库状态', '项目估算总投资（万元）', '建设规模及内容'];
                $header_data = ['title','duty_unit','reply','investment','content'];
                $list_do = $this->arrangeField($list,$library,$header_data);
                $libraryName = "入统库";
                break;
            case 6: //双千库
                foreach ($list as $k=>$v){
                    $figureWhere['pro_id'] = $v['id'];
                    $figureDetail = Db::name("project_pro_figure")->where($figureWhere)->order("id desc")->find();

                    $typeWhere['id'] = $figureDetail["problem_id"];
                    $typeName = $common->public_select("project_type",$where)->value("name");
                    $list[$k]['typeName'] = empty($typeName)?"":$typeName;

                    $list[$k]['problem_content'] = $figureDetail['problem_content'];
                    $list[$k]['content'] = $figureDetail['content'];
                }


                $header_arr = ['企业名称', '责任账号', '运行情况', '运营情况', '一级分类', '企业类型','走访时间','走访内容','存在的问题','诉求类型','问题内容'];
                $header_data = ['title','duty_person','condition_val','operation','menuTop','enterprise','visit_time','content','visit_remark','typeName','problem_content'];
                $list_do = $this->arrangeField($list,$library,$header_data);
                $libraryName = "双千库";
                break;
        }
        return self::export_excel($header_arr, $list_do,$libraryName);
    }

    //数据导出
    static function export_excel($head, $list, $filename = "导出数据")
    {
        vendor("PHPExcel.PHPExcel");
        vendor("PHPExcel.PHPExcel.Writer.Excel2007");
        //初始化PHPExcel()
        $objPHPExcel = new \PHPExcel();
        //设置保存版本格式
        $filename = $filename . '.xlsx';
        $char_index = range("A", "Z");
        // Excel 表格头
        foreach ($head as $key => $val) {
            $objPHPExcel->getActiveSheet()->setCellValue("{$char_index[$key]}1", $val);
        }
        // Excel body 部分
        foreach ($list as $key => $val) {
            $row = $key + 2;
            $col = 0;
            foreach ($val as $k => $v) {
                $objPHPExcel->getActiveSheet()->setCellValue("{$char_index[$col]}{$row}", $v);
                $col++;
            }
        }
        // 下载这个表格，在浏览器输出
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
        header("Content-Type:application/force-download");
        header("Content-Type:application/vnd.ms-execl");
        header("Content-Type:application/octet-stream");
        header("Content-Type:application/download");;
        header('Content-Disposition:attachment;filename=' . $filename . '');
        header("Content-Transfer-Encoding:binary");
        $PHPReader = new \PHPExcel_Writer_Excel2007($objPHPExcel);
        $PHPReader->save('php://output');
        die();
    }


    public function picupload()
    {
        try {
            $library = empty($_GET['library']) ? 1 : $_GET['library'];
            $file = request()->file('file');
            $thisWechat = Session::get("thisWechat");
            $path = ROOT_PATH . 'public' . DS . 'upload' . DS . "platform" . $thisWechat['id'];
            $info = $file->move($path);
            //获取文件（文件名），$info->getFilename()  ***********存储的文件名
            //获取文件（日期/文件名），$info->getSaveName()  **********文件地址
            $filename = $info->getSaveName();
            $filename = ROOT_PATH . 'public' . DS . 'upload' . DS . "platform" . $thisWechat['id'] . DS . $filename;
            if (!$filename) {
                $this->error($file->getError());
            }
            $this->import_exce($filename, $library);
            $black['code'] = 0;
            $black['msg'] = "导入成功";
        } catch (Exception $e) {
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }

        return $black;
    }

    //招商签约库项目导入
    function import_exce($file, $library)
    {
        ini_set("memory_limit", "80M");
        //$file = 'D:\phpstudy_pro\WWW\ticketing\public\upload\platform6\202103\964e3aa5a07d65cca89036e442b13754.xls';
        // 判断文件是什么格式
        $type = pathinfo($file);
        $exts = strtolower($type["extension"]);

        $PHPExcel = new \PHPExcel(); // 创建PHPExcel对象，注意，不能少了\
        if ($exts == 'xls') { // 如果excel文件后缀名为.xls，导入这个类
            vendor("PHPExcel.PHPExcel.Reader.Excel5");
            $PHPReader = new \PHPExcel_Reader_Excel5();
        } else if ($exts == 'xlsx') {
            vendor("PHPExcel.PHPExcel.Reader.Excel2007");
            $PHPReader = new \PHPExcel_Reader_Excel2007();
        }
        $PHPExcel = $PHPReader->load($file);
        $currentSheet = $PHPExcel->getSheet(0); // 获取表中的第一个工作表，如果要获取第二个，把0改为1，依次类推
        $allColumn = $currentSheet->getHighestColumn(); // 获取总列数
        $allRow = $currentSheet->getHighestRow(); // 获取总行数

        switch ($library) {
            case 1: //招商签约库添加
                $this->addSign($allRow, $allColumn, $PHPExcel, $library);
                break;
            case 2:  //项目预备库添加
                $this->addPrepare($allRow, $allColumn, $PHPExcel, $library);
                break;
            case 3:  //项目开工库添加
                $this->addStart($allRow, $allColumn, $PHPExcel, $library);
                break;
            case 4:  //重点项目库添加
                $this->addStress($allRow, $allColumn, $PHPExcel, $library);
                break;
            case 5:  //入统库添加
                $this->addIntegration($allRow, $allColumn, $PHPExcel, $library);
                break;
            case 6:  //双千库添加
                $this->addVisit($allRow, $allColumn, $PHPExcel, $library);
                break;
        }
    }

    //双千服务企业添加
    public function addVisit($allRow, $allColumn, $PHPExcel, $library)
    {
        $data = array();
        for ($j = 1; $j <= $allRow; $j++) {
            //从A列读取数据
            for ($k = 'A'; $k <= $allColumn; $k++) {
                // 读取单元格
                $data[$j][] = $PHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
            }
        }
        $thisWechat = Session::get("thisWechat");
        for ($i = 4; $i <= $allRow; $i++) {
            //数据库中的字段名和excel表中的字段
//            $mc = $PHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();;
            $data_p['title'] = $PHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();  //企业名称
            if (empty($data_p['title'])) {
                continue;
            }

            $menuTopVal = $PHPExcel->getActiveSheet()->getCell("C" . $i)->getValue(); //一级分类
            if (!empty($menuTopVal)) {
                $pro_type = config("pro_type");
                foreach ($pro_type as $k => $v) {
                    if ($menuTopVal == $v) {
                        $menuTopKey = $k;
                        $data_p['menuTop'] = $k;
                    }
                }
            }

            $enterprise = $PHPExcel->getActiveSheet()->getCell("D" . $i)->getValue(); //企业类型
            //查询是否存在该类别
            if (!empty($enterprise)) {
                $typeWhere['name'] = $enterprise;
                $typeWhere['uniacid'] = $thisWechat['id'];
                $typeWhere['type'] = 3;
                $typeId = Db::name("project_type")->where($typeWhere)->value("id");
                if (empty($typeId)) {
                    $typeData['name'] = $enterprise;
                    $typeData['uniacid'] = $thisWechat['id'];
                    $typeData['type'] = 3;
                    $typeData['add_id'] = Session::get("id");
                    $typeData['updatetime'] = date("Y-m-d h:i:s", time());
                    $typeId = Db::name("project_type")->insertGetId($typeData);
                }
                $data_p['enterprise'] = $typeId;
            }


            //培育类别/企业状况
            $newType = $PHPExcel->getActiveSheet()->getCell("E" . $i)->getValue(); //企业类型
            if ($menuTopKey == 1) {
                $cultivation = [1 => "计划年度进规企业", 2 => "计划月度进规企业"];
                if (!empty($newType)) {
                    foreach ($cultivation as $k => $v) {
                        if ($newType == $v) {
                            $data_p['cultivation'] = $k;
                        }
                    }
                }
            }
            if ($menuTopKey == 2) {
                $cultivation = [1 => "运行正常企业", 2 => "一般困难企业", 3 => "特别困难企业", 4 => "停产企业"];
                if (!empty($newType)) {
                    foreach ($cultivation as $k => $v) {
                        if ($newType == $v) {
                            $data_p['condition_val'] = $k;
                        }
                    }
                }
            }

            $data_p['duty_unit'] = $PHPExcel->getActiveSheet()->getCell("F" . $i)->getValue(); //责任单位

            $data_p['chargeman'] = $PHPExcel->getActiveSheet()->getCell("G" . $i)->getValue(); //组长
            $data_p['member'] = $PHPExcel->getActiveSheet()->getCell("H" . $i)->getValue(); //成员
            $data_p['liaison'] = $PHPExcel->getActiveSheet()->getCell("I" . $i)->getValue(); //联络员及电话
            $operation = $PHPExcel->getActiveSheet()->getCell("J" . $i)->getValue(); //是否运营正常
            $data_p['operation'] = ($operation == "是") ? 1 : 2;
            $visit_time = $PHPExcel->getActiveSheet()->getCell("K" . $i)->getValue(); //走访时间
            $data_p['visit_time'] = empty($visit_time)?0:$visit_time;
            $data_p['content'] = $PHPExcel->getActiveSheet()->getCell("L" . $i)->getValue(); //走访情况
            $data_p['visit_remark'] = $PHPExcel->getActiveSheet()->getCell("M" . $i)->getValue(); //存在的问题
            $data_p['remark'] = $PHPExcel->getActiveSheet()->getCell("N" . $i)->getValue(); //备注

            $data_p['industry'] = $PHPExcel->getActiveSheet()->getCell("O" . $i)->getValue(); //所属行业
            $data_p['product'] = $PHPExcel->getActiveSheet()->getCell("P" . $i)->getValue(); //主要产品
            $data_p['revenue'] = $PHPExcel->getActiveSheet()->getCell("Q" . $i)->getValue(); //累计应税收入
            $data_p['gauge'] = $PHPExcel->getActiveSheet()->getCell("R" . $i)->getValue(); //拟进规时间
            $data_p['project_chief'] = $PHPExcel->getActiveSheet()->getCell("S" . $i)->getValue(); //企业联系人及电话
            $data_p['cause'] = '';
            $data_p['uniacid'] = $thisWechat['id'];
            $data_p['library'] = $library;
            $proWhere['library'] = $library;
            $proWhere['title'] = $data_p['title'];
            $project = Db::name("project_pro")->where($proWhere)->value("id");
            if (empty($project)) {
                $data_p['addtime'] = date("Y-m-d h:i:s", time());
                $data_p['add_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->insertGetId($data_p);
            } else {
                $data_p['updatetime'] = date("Y-m-d h:i:s", time());
                $data_p['update_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->where(['id' => $project])->update($data_p);
            }
        }
    }


    //招商签约库添加
    public function addSign($allRow, $allColumn, $PHPExcel, $library)
    {

        $data = array();
        for ($j = 1; $j <= $allRow; $j++) {
            //从A列读取数据
            for ($k = 'A'; $k <= $allColumn; $k++) {
                // 读取单元格
                $data[$j][] = $PHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
            }
        }
        $thisWechat = Session::get("thisWechat");
        for ($i = 5; $i <= $allRow; $i++) {
            //数据库中的字段名和excel表中的字段
//            $mc = $PHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();;
//            $data_p['leader'] = $PHPExcel->getActiveSheet()->getCell("B" .$i)->getValue();  //县级领导
            $data_p['title'] = $PHPExcel->getActiveSheet()->getCell("B" . $i)->getValue(); //项目名称
            if (empty($data_p['title'])) {
                continue;
            }
            $data_p['Investor'] = $PHPExcel->getActiveSheet()->getCell("C" . $i)->getValue(); //投资方
            $data_p['investment'] = $PHPExcel->getActiveSheet()->getCell("D" . $i)->getValue(); //总投资
            $data_p['address'] = $PHPExcel->getActiveSheet()->getCell("E" . $i)->getValue(); //拟选址
            $data_p['content'] = $PHPExcel->getActiveSheet()->getCell("F" . $i)->getValue(); //主要建设内容及规模


            $IndustrialChain = $PHPExcel->getActiveSheet()->getCell("G" . $i)->getValue(); //所属产业链
            //查询是否存在该类别
            if (!empty($IndustrialChain)) {
                $typeWhere['name'] = $IndustrialChain;
                $typeWhere['uniacid'] = $thisWechat['id'];
                $typeWhere['type'] = 2;
                $typeId = Db::name("project_type")->where($typeWhere)->value("id");
                if (empty($typeId)) {
                    $typeData['name'] = $IndustrialChain;
                    $typeData['uniacid'] = $thisWechat['id'];
                    $typeData['type'] = 2;
                    $typeData['add_id'] = Session::get("id");
                    $typeData['updatetime'] = date("Y-m-d h:i:s", time());
                    $typeId = Db::name("project_type")->insertGetId($typeData);
                }
                $data_p['IndustrialChain'] = $typeId;
            }
            $data_p['cardMeeting'] = $PHPExcel->getActiveSheet()->getCell("H" . $i)->getValue();  //通过论证会时间
            $data_p['signTime'] = $PHPExcel->getActiveSheet()->getCell("I" . $i)->getValue();  //计划签约时间
            $data_p['actualsignTime'] = $PHPExcel->getActiveSheet()->getCell("J" . $i)->getValue();  //实际签约时间
//            if(!empty($cardMeeting)){
//                 = date("Y-m-d",strtotime($cardMeeting));
//            }
//            if(!empty($signTime)){
//                 = date("Y-m-d",strtotime($signTime));
//            }

            $data_p['duty_unit'] = $PHPExcel->getActiveSheet()->getCell("K" . $i)->getValue(); //责任单位
//            $data_p['project_chief'] = $PHPExcel->getActiveSheet()->getCell("L" .$i)->getValue(); //责任人
            $data_p['signRemark'] = $PHPExcel->getActiveSheet()->getCell("L" . $i)->getValue(); //需提请协调事项
            $data_p['uniacid'] = $thisWechat['id'];
            $data_p['library'] = $library;
            $data_p['cause'] = '';
            $proWhere['library'] = $library;
            $proWhere['title'] = $data_p['title'];

            $project = Db::name("project_pro")->where($proWhere)->value("id");
            if (empty($project)) {
                $data_p['addtime'] = date("Y-m-d h:i:s", time());
                $data_p['add_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->insertGetId($data_p);
            } else {
                $data_p['updatetime'] = date("Y-m-d h:i:s", time());
                $data_p['update_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->where(['id' => $project])->update($data_p);
            }
        }
    }

    //项目预备库添加
    public function addPrepare($allRow, $allColumn, $PHPExcel, $library)
    {

        $data = array();
        for ($j = 1; $j <= $allRow; $j++) {
            //从A列读取数据
            for ($k = 'A'; $k <= $allColumn; $k++) {
                // 读取单元格
                $data[$j][] = $PHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
            }
        }
        $thisWechat = Session::get("thisWechat");
        for ($i = 5; $i <= $allRow; $i++) {
            //数据库中的字段名和excel表中的字段
//            $mc = $PHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();;
            $data_p['duty_unit'] = $PHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();  //责任单位
            $data_p['title'] = $PHPExcel->getActiveSheet()->getCell("C" . $i)->getValue(); //项目名称
            if (empty($data_p['title'])) {
                continue;
            }
            $data_p['address'] = $PHPExcel->getActiveSheet()->getCell("D" . $i)->getValue(); //选址
            $data_p['duty_person'] = $PHPExcel->getActiveSheet()->getCell("E" . $i)->getValue(); //责任人
            $data_p['cause'] = '';
            $newTypeId = 0;
            $menuTopVal = $PHPExcel->getActiveSheet()->getCell("F" . $i)->getValue(); //一级分类
            if (!empty($menuTopVal)) {
                $typeWhere['name'] = $menuTopVal;
                $typeWhere['uniacid'] = $thisWechat['id'];
                $typeWhere['type'] = 4;
                $typeWhere['pid'] = 0;
                $newTypeId = Db::name("project_type")->where($typeWhere)->value("id");
                $data_p['menuTop'] = $newTypeId;
            }

            $project_type = $PHPExcel->getActiveSheet()->getCell("G" . $i)->getValue(); //项目类别
            if (!empty($project_type)) {
                $typeWhere['name'] = $project_type;
                $typeWhere['uniacid'] = $thisWechat['id'];
                $typeWhere['type'] = 4;
                $typeWhere['pid'] = $newTypeId;
                $project_type = Db::name("project_type")->where($typeWhere)->value("id");
                $data_p['project_type'] = $project_type;
            }

            $data_p['content'] = $PHPExcel->getActiveSheet()->getCell("H" . $i)->getValue(); //主要建设内容及规模
            $data_p['investment'] = $PHPExcel->getActiveSheet()->getCell("I" . $i)->getValue(); //总投资
            //时序
            $plan['plan_content'] = $PHPExcel->getActiveSheet()->getCell("J" . $i)->getValue();  //重要工作节点推进计划
            $plan['plan_investment'] = $PHPExcel->getActiveSheet()->getCell("K" . $i)->getValue();  //计划投资
            $data_p['plan_onstream_time'] = $PHPExcel->getActiveSheet()->getCell("L" . $i)->getValue(); //计划开工时间

            if (empty($data_p['plan_onstream_time'])) {
                throw new Exception("项目【" . $data_p['title'] . "】计划开工时间不能为空");
            }

//            if(!empty($plan_onstream_time)){
//                $data_p['plan_onstream_time'] = date("Y-m-d",strtotime($plan_onstream_time));
//            }

            $data_p['prepareRemark'] = $PHPExcel->getActiveSheet()->getCell("M" . $i)->getValue(); //需提请协调事项


            $data_p['uniacid'] = $thisWechat['id'];
            $data_p['library'] = $library;
            $proWhere['library'] = $library;
            $proWhere['title'] = $data_p['title'];
            $project = Db::name("project_pro")->where($proWhere)->value("id");
            if (empty($project)) {
                $data_p['addtime'] = date("Y-m-d h:i:s", time());
                $data_p['add_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->insertGetId($data_p);
                $plan['pro_id'] = $pro_id;
                $plan['plan_title'] = date("Y", time());
                Db::name("project_pro_plan")->insertGetId($plan);
            } else {
                $data_p['updatetime'] = date("Y-m-d h:i:s", time());
                $data_p['update_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->where(['id' => $project])->update($data_p);
            }
        }
    }

    //项目开工库添加
    public function addStart($allRow, $allColumn, $PHPExcel, $library)
    {

        $data = array();
        for ($j = 1; $j <= $allRow; $j++) {
            //从A列读取数据
            for ($k = 'A'; $k <= $allColumn; $k++) {
                // 读取单元格
                $data[$j][] = $PHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
            }
        }
        $thisWechat = Session::get("thisWechat");
        for ($i = 5; $i <= $allRow; $i++) {
            //数据库中的字段名和excel表中的字段
//            $mc = $PHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();;
            $data_p['duty_unit'] = $PHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();  //责任单位
            $data_p['leader'] = $PHPExcel->getActiveSheet()->getCell("C" . $i)->getValue();  //县级领导
            $data_p['title'] = $PHPExcel->getActiveSheet()->getCell("D" . $i)->getValue(); //项目名称
            if (empty($data_p['title'])) {
                continue;
            }
            $data_p['address'] = $PHPExcel->getActiveSheet()->getCell("E" . $i)->getValue(); //选址


            $data_p['duty_person'] = $PHPExcel->getActiveSheet()->getCell("F" . $i)->getValue(); //责任人
            $data_p['cause'] = '';
            $newTypeId = 0;
            $menuTopVal = $PHPExcel->getActiveSheet()->getCell("G" . $i)->getValue(); //一级分类
            if (!empty($menuTopVal)) {
                $typeWhere['name'] = $menuTopVal;
                $typeWhere['uniacid'] = $thisWechat['id'];
                $typeWhere['type'] = 4;
                $typeWhere['pid'] = 0;
                $newTypeId = Db::name("project_type")->where($typeWhere)->value("id");
                $data_p['menuTop'] = $newTypeId;
            }

            $project_type = $PHPExcel->getActiveSheet()->getCell("H" . $i)->getValue(); //项目类别
            if (!empty($project_type)) {
                $typeWhere['name'] = $project_type;
                $typeWhere['uniacid'] = $thisWechat['id'];
                $typeWhere['type'] = 4;
                $typeWhere['pid'] = $newTypeId;
                $project_type = Db::name("project_type")->where($typeWhere)->value("id");
                $data_p['project_type'] = $project_type;
            }


            $data_p['content'] = $PHPExcel->getActiveSheet()->getCell("I" . $i)->getValue(); //主要建设内容及规模
            $data_p['investment'] = $PHPExcel->getActiveSheet()->getCell("J" . $i)->getValue(); //总投资


            //时序
            $plan['plan_content'] = $PHPExcel->getActiveSheet()->getCell("K" . $i)->getValue();  //重要工作节点推进计划
            $plan['plan_investment'] = $PHPExcel->getActiveSheet()->getCell("L" . $i)->getValue();  //计划投资


            $data_p['arrange_onstream_time'] = $PHPExcel->getActiveSheet()->getCell("M" . $i)->getValue(); //合作协议约定开工时间
            $data_p['onstream_time'] = $PHPExcel->getActiveSheet()->getCell("N" . $i)->getValue(); //实际开工时间
            $data_p['arrange_complete_time'] = $PHPExcel->getActiveSheet()->getCell("O" . $i)->getValue(); //合作协议约定竣工时间
            $data_p['plan_complete_time'] = $PHPExcel->getActiveSheet()->getCell("P" . $i)->getValue(); //计划竣工时间
//            if(!empty($arrange_onstream_time)){
//                $data_p['arrange_onstream_time'] = date("Y-m-d",strtotime($arrange_onstream_time));
//            }
//            if(!empty($onstream_time)){
//                $data_p['onstream_time'] = date("Y-m-d",strtotime($onstream_time));
//            }
//            if(!empty($arrange_complete_time)){
//                $data_p['arrange_complete_time'] = date("Y-m-d",strtotime($arrange_complete_time));
//            }
//            if(!empty($plan_complete_time)){
//                $data_p['plan_complete_time'] = date("Y-m-d",strtotime($plan_complete_time));
//            }

//            $data_p['project_chief'] = $PHPExcel->getActiveSheet()->getCell("N" .$i)->getValue(); //责任人

            $record = $PHPExcel->getActiveSheet()->getCell("Q" . $i)->getValue(); //备案或立项
            $contract = $PHPExcel->getActiveSheet()->getCell("R" . $i)->getValue(); //合同
            $scene = $PHPExcel->getActiveSheet()->getCell("S" . $i)->getValue(); //项目现场
            $data_p['record'] = ($record == "是") ? 1 : 2;
            $data_p['contract'] = ($contract == "是") ? 1 : 2;
            $data_p['scene'] = ($scene == "是") ? 1 : 2;

            $data_p['startRemark'] = $PHPExcel->getActiveSheet()->getCell("T" . $i)->getValue(); //需提请协调事项

            $data_p['uniacid'] = $thisWechat['id'];
            $data_p['library'] = $library;
            $proWhere['library'] = $library;
            $proWhere['title'] = $data_p['title'];
            $project = Db::name("project_pro")->where($proWhere)->value("id");
            if (empty($project)) {
                $data_p['addtime'] = date("Y-m-d h:i:s", time());
                $data_p['add_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->insertGetId($data_p);
                $plan['pro_id'] = $pro_id;
                $plan['plan_title'] = date("Y", time());
                Db::name("project_pro_plan")->insertGetId($plan);
            } else {
                $data_p['updatetime'] = date("Y-m-d h:i:s", time());
                $data_p['update_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->where(['id' => $project])->update($data_p);
            }
        }
    }

    //重点项目库添加
    public function addStress($allRow, $allColumn, $PHPExcel, $library)
    {
        $data = array();
        for ($j = 1; $j <= $allRow; $j++) {
            //从A列读取数据
            for ($k = 'A'; $k <= $allColumn; $k++) {
                // 读取单元格
                $data[$j][] = $PHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
            }
        }
        $thisWechat = Session::get("thisWechat");
        for ($i = 5; $i <= $allRow; $i++) {
            //数据库中的字段名和excel表中的字段
//            $mc = $PHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();;
            $data_p['leader'] = $PHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();  //县级领导
            $data_p['title'] = $PHPExcel->getActiveSheet()->getCell("C" . $i)->getValue(); //项目名称
            if (empty($data_p['title'])) {
                continue;
            }
            $data_p['address'] = $PHPExcel->getActiveSheet()->getCell("D" . $i)->getValue(); //选址
            $data_p['content'] = $PHPExcel->getActiveSheet()->getCell("E" . $i)->getValue(); //主要建设内容及规模
            $data_p['cause'] = '';
            $project_type = $PHPExcel->getActiveSheet()->getCell("F" . $i)->getValue(); //项目类别
            //查询是否存在该类别
            if (!empty($project_type)) {
                $typeWhere['name'] = $project_type;
                $typeWhere['uniacid'] = $thisWechat['id'];
                $typeId = Db::name("project_type")->where($typeWhere)->value("id");
                if (empty($typeId)) {
                    $typeData['name'] = $project_type;
                    $typeData['uniacid'] = $thisWechat['id'];;
                    $typeData['add_id'] = Session::get("id");
                    $typeData['updatetime'] = date("Y-m-d h:i:s", time());
                    $typeId = Db::name("project_type")->insertGetId($typeData);
                }
                $data_p['project_type'] = $typeId;
            }
            $data_p['investment'] = $PHPExcel->getActiveSheet()->getCell("G" . $i)->getValue(); //总投资
            //时序
            $plan['plan_content'] = $PHPExcel->getActiveSheet()->getCell("H" . $i)->getValue();  //重要工作节点推进计划
            $plan['plan_investment'] = $PHPExcel->getActiveSheet()->getCell("I" . $i)->getValue();  //计划投资
            $data_p['plan_onstream_time'] = $PHPExcel->getActiveSheet()->getCell("J" . $i)->getValue(); //计划开工时间
            $data_p['plan_complete_time'] = $PHPExcel->getActiveSheet()->getCell("K" . $i)->getValue(); //计划竣工时间
//            if(!empty($plan_onstream_time)){
//                $data_p['plan_onstream_time'] = date("Y-m-d",strtotime($plan_onstream_time));
//            }
//            if(!empty($plan_complete_time)){
//                $data_p['plan_complete_time'] = date("Y-m-d",strtotime($plan_complete_time));
//            }
            $data_p['duty_unit'] = $PHPExcel->getActiveSheet()->getCell("L" . $i)->getValue(); //牵头责任单位
            $data_p['project_chief'] = $PHPExcel->getActiveSheet()->getCell("M" . $i)->getValue(); //责任人
            $data_p['difficulty'] = $PHPExcel->getActiveSheet()->getCell("N" . $i)->getValue(); //推进问题
            $data_p['uniacid'] = $thisWechat['id'];
            $data_p['library'] = $library;

            $proWhere['library'] = $library;
            $proWhere['title'] = $data_p['title'];
            $project = Db::name("project_pro")->where($proWhere)->value("id");
            if (empty($project)) {
                $data_p['addtime'] = date("Y-m-d h:i:s", time());
                $data_p['add_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->insertGetId($data_p);
                $plan['pro_id'] = $pro_id;
                $plan['plan_title'] = date("Y", time());
                Db::name("project_pro_plan")->insertGetId($plan);
            } else {
                $data_p['updatetime'] = date("Y-m-d h:i:s", time());
                $data_p['update_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->where(['id' => $project])->update($data_p);
            }
        }
    }


    //入统库添加
    public function addIntegration($allRow, $allColumn, $PHPExcel, $library)
    {
        $data = array();
        for ($j = 1; $j <= $allRow; $j++) {
            //从A列读取数据
            for ($k = 'A'; $k <= $allColumn; $k++) {
                // 读取单元格
                $data[$j][] = $PHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
            }
        }
        $thisWechat = Session::get("thisWechat");
        for ($i = 5; $i <= $allRow; $i++) {
            //数据库中的字段名和excel表中的字段
//            $mc = $PHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();;
            $data_p['title'] = $PHPExcel->getActiveSheet()->getCell("B" . $i)->getValue(); //项目名称
            if (empty($data_p['title'])) {
                continue;
            }
            $data_p['address'] = $PHPExcel->getActiveSheet()->getCell("C" . $i)->getValue(); //选址
            $data_p['content'] = $PHPExcel->getActiveSheet()->getCell("D" . $i)->getValue(); //主要建设内容及规模
            $data_p['investment'] = $PHPExcel->getActiveSheet()->getCell("E" . $i)->getValue(); //总投资
            $data_p['initial_investment_time'] = $PHPExcel->getActiveSheet()->getCell("F" . $i)->getValue();  //启报投资时间
            $data_p['planned_production_time'] = $PHPExcel->getActiveSheet()->getCell("G" . $i)->getValue();  //计划投产时间
//            if(!empty($initial_investment_time)){
//                $data_p['initial_investment_time'] = date("Y-m-d",strtotime($initial_investment_time));
//            }
//            if(!empty($planned_production_time)){
//                $data_p['planned_production_time'] = date("Y-m-d",strtotime($planned_production_time));
//            }
            $data_p['cause'] = '';
            $data_p['duty_unit'] = $PHPExcel->getActiveSheet()->getCell("H" . $i)->getValue(); //责任单位
            $data_p['duty_person'] = $PHPExcel->getActiveSheet()->getCell("I" . $i)->getValue(); //责任人
            $data_p['integrationRemark'] = $PHPExcel->getActiveSheet()->getCell("J" . $i)->getValue(); //存在的问题
            $data_p['warehousingTime'] = $PHPExcel->getActiveSheet()->getCell("K" . $i)->getValue(); //入库时间

            $reply = $PHPExcel->getActiveSheet()->getCell("L" . $i)->getValue(); //入库状态
            $replyVal = [1 => "已启报", 2 => "已报竭"];
            if (!empty($reply)) {
                foreach ($replyVal as $k => $v) {
                    if ($reply == $v) {
                        $data_p['reply'] = $k;
                    }
                }
            }

            $data_p['uniacid'] = $thisWechat['id'];
            $data_p['library'] = $library;
            $proWhere['library'] = $library;
            $proWhere['title'] = $data_p['title'];
            $project = Db::name("project_pro")->where($proWhere)->value("id");
            if (empty($project)) {
                $data_p['addtime'] = date("Y-m-d h:i:s", time());
                $data_p['add_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->insertGetId($data_p);
            } else {
                $data_p['updatetime'] = date("Y-m-d h:i:s", time());
                $data_p['update_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->where(['id' => $project])->update($data_p);
            }
        }
    }


    //招商签约库项目导入
    function import_exce2($file)
    {
        ini_set("memory_limit", "80M");
        //$file = 'D:\phpstudy_pro\WWW\ticketing\public\upload\platform6\202103\964e3aa5a07d65cca89036e442b13754.xls';
        // 判断文件是什么格式
        $type = pathinfo($file);
        $exts = strtolower($type["extension"]);

        $PHPExcel = new \PHPExcel(); // 创建PHPExcel对象，注意，不能少了\
        if ($exts == 'xls') { // 如果excel文件后缀名为.xls，导入这个类
            vendor("PHPExcel.PHPExcel.Reader.Excel5");
            $PHPReader = new \PHPExcel_Reader_Excel5();
        } else if ($exts == 'xlsx') {
            vendor("PHPExcel.PHPExcel.Reader.Excel2007");
            $PHPReader = new \PHPExcel_Reader_Excel2007();
        }
        $PHPExcel = $PHPReader->load($file);
        $currentSheet = $PHPExcel->getSheet(0); // 获取表中的第一个工作表，如果要获取第二个，把0改为1，依次类推
        $allColumn = $currentSheet->getHighestColumn(); // 获取总列数
        $allRow = $currentSheet->getHighestRow(); // 获取总行数

        $data = array();
        for ($j = 1; $j <= $allRow; $j++) {
            //从A列读取数据
            for ($k = 'A'; $k <= $allColumn; $k++) {
                // 读取单元格
                $data[$j][] = $PHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
            }
        }
        $thisWechat = Session::get("thisWechat");
        for ($i = 5; $i <= $allRow; $i++) {
            //数据库中的字段名和excel表中的字段
//            $mc = $PHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();;
            $data_p['leader'] = $PHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();  //县级领导
            $data_p['title'] = $PHPExcel->getActiveSheet()->getCell("C" . $i)->getValue(); //项目名称
            if (empty($data_p['title'])) {
                continue;
            }
            $data_p['address'] = $PHPExcel->getActiveSheet()->getCell("D" . $i)->getValue(); //选址
            $data_p['content'] = $PHPExcel->getActiveSheet()->getCell("E" . $i)->getValue(); //主要建设内容及规模
            $project_type = $PHPExcel->getActiveSheet()->getCell("F" . $i)->getValue(); //项目类别
            //查询是否存在该类别

            $data_p['cause'] = '';
            if (!empty($project_type)) {
                $typeWhere['name'] = $project_type;
                $typeWhere['uniacid'] = $thisWechat['id'];
                $typeId = Db::name("project_type")->where($typeWhere)->value("id");
                if (empty($typeId)) {
                    $typeData['name'] = $project_type;
                    $typeData['uniacid'] = $thisWechat['id'];;
                    $typeData['add_id'] = Session::get("id");
                    $typeData['updatetime'] = date("Y-m-d h:i:s", time());
                    $typeId = Db::name("project_type")->insertGetId($typeData);
                }
                $data_p['project_type'] = $typeId;
            }

            $data_p['investment'] = $PHPExcel->getActiveSheet()->getCell("G" . $i)->getValue(); //总投资
            //时序
            $plan['plan_content'] = $PHPExcel->getActiveSheet()->getCell("H" . $i)->getValue();  //重要工作节点推进计划
            $plan['plan_investment'] = $PHPExcel->getActiveSheet()->getCell("I" . $i)->getValue();  //计划投资
            $plan_onstream_time = $PHPExcel->getActiveSheet()->getCell("J" . $i)->getValue(); //计划开工时间
            $plan_complete_time = $PHPExcel->getActiveSheet()->getCell("K" . $i)->getValue(); //计划竣工时间
            if (!empty($plan_onstream_time)) {
                $data_p['plan_onstream_time'] = date("Y-m-d", strtotime($plan_onstream_time));
            }
            if (!empty($plan_complete_time)) {
                $data_p['plan_complete_time'] = date("Y-m-d", strtotime($plan_complete_time));
            }
            $data_p['duty_unit'] = $PHPExcel->getActiveSheet()->getCell("L" . $i)->getValue(); //牵头责任单位
            $data_p['duty_person'] = $PHPExcel->getActiveSheet()->getCell("M" . $i)->getValue(); //责任人
            $data_p['difficulty'] = $PHPExcel->getActiveSheet()->getCell("N" . $i)->getValue(); //推进问题
            $data_p['uniacid'] = $thisWechat['id'];
            $data_p['library'] = 2;
            $record = $PHPExcel->getActiveSheet()->getCell("O" . $i)->getValue(); //备案或立项
            $contract = $PHPExcel->getActiveSheet()->getCell("P" . $i)->getValue(); //合同
            $scene = $PHPExcel->getActiveSheet()->getCell("Q" . $i)->getValue(); //项目现场
            $data_p['record'] = ($record == "是") ? 1 : 2;
            $data_p['contract'] = ($contract == "是") ? 1 : 2;
            $data_p['scene'] = ($scene == "是") ? 1 : 2;

            $project = Db::name("project_pro")->where(['title' => $data_p['title']])->value("id");
            if (empty($project)) {
                $data_p['addtime'] = date("Y-m-d h:i:s", time());
                $data_p['add_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->insertGetId($data_p);
                $plan['pro_id'] = $pro_id;
                $plan['plan_title'] = date("Y", time());
                Db::name("project_pro_plan")->insertGetId($plan);
            } else {
                $data_p['updatetime'] = date("Y-m-d h:i:s", time());
                $data_p['update_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->where(['id' => $project])->update($data_p);
            }
        }
    }

    //招商签约库项目导入
    function import_excel($file)
    {
        ini_set("memory_limit", "80M");
        //$file = 'D:\phpstudy_pro\WWW\ticketing\public\upload\platform6\202103\964e3aa5a07d65cca89036e442b13754.xls';
        // 判断文件是什么格式
        $type = pathinfo($file);
        $exts = strtolower($type["extension"]);

        $PHPExcel = new \PHPExcel(); // 创建PHPExcel对象，注意，不能少了\
        if ($exts == 'xls') { // 如果excel文件后缀名为.xls，导入这个类
            vendor("PHPExcel.PHPExcel.Reader.Excel5");
            $PHPReader = new \PHPExcel_Reader_Excel5();
        } else if ($exts == 'xlsx') {
            vendor("PHPExcel.PHPExcel.Reader.Excel2007");
            $PHPReader = new \PHPExcel_Reader_Excel2007();
        }
        $PHPExcel = $PHPReader->load($file);
        $currentSheet = $PHPExcel->getSheet(0); // 获取表中的第一个工作表，如果要获取第二个，把0改为1，依次类推
        $allColumn = $currentSheet->getHighestColumn(); // 获取总列数
        $allRow = $currentSheet->getHighestRow(); // 获取总行数

        $data = array();
        for ($j = 1; $j <= $allRow; $j++) {
            //从A列读取数据
            for ($k = 'A'; $k <= $allColumn; $k++) {
                // 读取单元格
                $data[$j][] = $PHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
            }
        }
        $thisWechat = Session::get("thisWechat");
        for ($i = 5; $i <= $allRow; $i++) {
            //数据库中的字段名和excel表中的字段
//            $mc = $PHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();;
            $data_p['leader'] = $PHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();  //县级领导
            $data_p['title'] = $PHPExcel->getActiveSheet()->getCell("C" . $i)->getValue(); //项目名称
            if (empty($data_p['title'])) {
                continue;
            }
            $data_p['cause'] = '';
            $data_p['address'] = $PHPExcel->getActiveSheet()->getCell("D" . $i)->getValue(); //选址
            $data_p['content'] = $PHPExcel->getActiveSheet()->getCell("E" . $i)->getValue(); //主要建设内容及规模
            $project_type = $PHPExcel->getActiveSheet()->getCell("F" . $i)->getValue(); //项目类别
            //查询是否存在该类别
            if (!empty($project_type)) {
                $typeWhere['name'] = $project_type;
                $typeWhere['uniacid'] = $thisWechat['id'];
                $typeId = Db::name("project_type")->where($typeWhere)->value("id");
                if (empty($typeId)) {
                    $typeData['name'] = $project_type;
                    $typeData['uniacid'] = $thisWechat['id'];;
                    $typeData['add_id'] = Session::get("id");
                    $typeData['updatetime'] = date("Y-m-d h:i:s", time());
                    $typeId = Db::name("project_type")->insertGetId($typeData);
                }
                $data_p['project_type'] = $typeId;
            }
            $data_p['investment'] = $PHPExcel->getActiveSheet()->getCell("G" . $i)->getValue(); //总投资
            //时序
            $plan['plan_content'] = $PHPExcel->getActiveSheet()->getCell("H" . $i)->getValue();  //重要工作节点推进计划
            $plan['plan_investment'] = $PHPExcel->getActiveSheet()->getCell("I" . $i)->getValue();  //计划投资
            $plan_onstream_time = $PHPExcel->getActiveSheet()->getCell("J" . $i)->getValue(); //计划开工时间
            $plan_complete_time = $PHPExcel->getActiveSheet()->getCell("K" . $i)->getValue(); //计划竣工时间
            if (!empty($plan_onstream_time)) {
                $data_p['plan_onstream_time'] = date("Y-m-d", strtotime($plan_onstream_time));
            }
            if (!empty($plan_complete_time)) {
                $data_p['plan_complete_time'] = date("Y-m-d", strtotime($plan_complete_time));
            }
            $data_p['duty_unit'] = $PHPExcel->getActiveSheet()->getCell("L" . $i)->getValue(); //牵头责任单位
            $data_p['duty_person'] = $PHPExcel->getActiveSheet()->getCell("M" . $i)->getValue(); //责任人
            $data_p['difficulty'] = $PHPExcel->getActiveSheet()->getCell("N" . $i)->getValue(); //推进问题
            $data_p['uniacid'] = $thisWechat['id'];
            $data_p['library'] = 1;
            $project = Db::name("project_pro")->where(['title' => $data_p['title']])->value("id");
            if (empty($project)) {
                $data_p['addtime'] = date("Y-m-d h:i:s", time());
                $data_p['add_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->insertGetId($data_p);
                $plan['pro_id'] = $pro_id;
                $plan['plan_title'] = date("Y", time());
                Db::name("project_pro_plan")->insertGetId($plan);
            } else {
                $data_p['updatetime'] = date("Y-m-d h:i:s", time());
                $data_p['update_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->where(['id' => $project])->update($data_p);
            }
        }
    }


    /**
     * 导入excel文件
     * @param  string $file excel文件路径
     * @return array        excel文件内容数组 $file
     */
    function import_exce4($file, $library)
    {
        ini_set("memory_limit", "80M");
        //$file = 'D:\phpstudy_pro\WWW\ticketing\public\upload\platform6\202103\964e3aa5a07d65cca89036e442b13754.xls';
        // 判断文件是什么格式
        $type = pathinfo($file);
        $exts = strtolower($type["extension"]);

        $PHPExcel = new \PHPExcel(); // 创建PHPExcel对象，注意，不能少了\
        if ($exts == 'xls') { // 如果excel文件后缀名为.xls，导入这个类
            vendor("PHPExcel.PHPExcel.Reader.Excel5");
            $PHPReader = new \PHPExcel_Reader_Excel5();
        } else if ($exts == 'xlsx') {
            vendor("PHPExcel.PHPExcel.Reader.Excel2007");
            $PHPReader = new \PHPExcel_Reader_Excel2007();
        }
        $PHPExcel = $PHPReader->load($file);
        $currentSheet = $PHPExcel->getSheet(0); // 获取表中的第一个工作表，如果要获取第二个，把0改为1，依次类推
        $allColumn = $currentSheet->getHighestColumn(); // 获取总列数
        $allRow = $currentSheet->getHighestRow(); // 获取总行数

        $data = array();
        for ($j = 1; $j <= $allRow; $j++) {
            //从A列读取数据
            for ($k = 'A'; $k <= $allColumn; $k++) {
                // 读取单元格
                $data[$j][] = $PHPExcel->getActiveSheet()->getCell("$k$j")->getValue();
            }
        }
        $thisWechat = Session::get("thisWechat");

        for ($i = 5; $i <= $allRow; $i++) {
            $ztime = time();
            $timee = microtime($ztime);
            //数据库中的字段名和excel表中的字段
//            $mc = $PHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();;
            $data_p['leader'] = $PHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();
            $data_p['title'] = $PHPExcel->getActiveSheet()->getCell("C" . $i)->getValue();
            if (empty($data_p['title'])) {
                continue;
            }
            $data_p['content'] = $PHPExcel->getActiveSheet()->getCell("D" . $i)->getValue();
            $data_p['investment'] = $PHPExcel->getActiveSheet()->getCell("E" . $i)->getValue();
            $plan['plan_content'] = $PHPExcel->getActiveSheet()->getCell("F" . $i)->getValue();
            $plan['plan_investment'] = $PHPExcel->getActiveSheet()->getCell("G" . $i)->getValue();

            $onstream_time = $PHPExcel->getActiveSheet()->getCell("H" . $i)->getValue();
            $complete_time = $PHPExcel->getActiveSheet()->getCell("I" . $i)->getValue();
            if (!empty($onstream_time)) {
                $data_p['onstream_time'] = date("Y-m-d", strtotime($onstream_time));
            }
            if (!empty($complete_time)) {
                $data_p['plan_complete_time'] = date("Y-m-d", strtotime($complete_time));
            }
            $duty_unit = $PHPExcel->getActiveSheet()->getCell("J" . $i)->getValue();
            $duty_unit_v = explode(";", $duty_unit);
            foreach ($duty_unit_v as $item) {
                $item = trim($item, " ");
                $whereA['name'] = $item;
                $dic_id = Db::name("project_dictionaries")->where($whereA)->value("id");
                if (empty($dic_id)) {
                    $dictionaries['name'] = $item;
                    $dictionaries['uniacid'] = $thisWechat['id'];;
                    $dictionaries['add_id'] = Session::get("id");
                    $dictionaries['updatetime'] = date("Y-m-d h:i:s", time());
                    Db::name("project_dictionaries")->insertGetId($dictionaries);
                }
            }
            $data_p['duty_unit'] = $duty_unit;
            $data_p['duty_person'] = $PHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();
            $data_p['remark'] = $PHPExcel->getActiveSheet()->getCell("K" . $i)->getValue();
            $data_p['uniacid'] = $thisWechat['id'];
            $project = Db::name("project_pro")->where(['title' => $data_p['title']])->value("id");
            if (empty($project)) {
                $data_p['addtime'] = date("Y-m-d h:i:s", time());
                $data_p['add_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->insertGetId($data_p);
                $plan['pro_id'] = $pro_id;
                $plan['plan_title'] = date("Y", time());
                Db::name("project_pro_plan")->insertGetId($plan);
            } else {
                $data_p['updatetime'] = date("Y-m-d h:i:s", time());
                $data_p['update_id'] = Session::get("id");
                $pro_id = Db::name("project_pro")->where(['id' => $project])->update($data_p);
            }
        }
    }

}